#include <GL/glut.h>
int figure;

void drawObject() {
	switch(figure) {
		case 1:
			glutSolidSphere(1.0, 20, 20);
		break;
		
		case 2:
			glutSolidCube(2.0);
		break;
		
		case 3:
			glutSolidTeapot(0.75);
		break;
	}
}

void myinit(void){
    GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 };
    GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat position[] = { 0.0, 3.0, 2.0, 0.0 };
    GLfloat lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 };
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
    glLightfv(GL_LIGHT0, GL_POSITION, position);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glClearColor(1.0, 1.0, 1.0, 0.0);
    figure = 1;
}
void display(void)
{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
      glTranslatef (-3.75, 3.0, 0.0);
      drawObject();
    glPopMatrix();

    glPushMatrix();
      glTranslatef (-3.75, 0.0, 0.0);
      drawObject();
    glPopMatrix();

    glPushMatrix();
      glTranslatef (-3.75, -3.0, 0.0);
      drawObject();
    glPopMatrix();

    glPushMatrix();
      glTranslatef (-1.25, 3.0, 0.0);
      drawObject();
    glPopMatrix();

    glPushMatrix();
      glTranslatef (-1.25, 0.0, 0.0);
      drawObject();
    glPopMatrix();

    glPushMatrix();
      glTranslatef (-1.25, -3.0, 0.0);
      drawObject();
    glPopMatrix();

    glPushMatrix();
      glTranslatef (1.25, 3.0, 0.0);
      drawObject();
    glPopMatrix();

    glPushMatrix();
      glTranslatef (1.25, 0.0, 0.0);
      drawObject();
    glPopMatrix();

    glPushMatrix();
      glTranslatef (1.25, -3.0, 0.0);
      drawObject();
    glPopMatrix();

    glPushMatrix();
      glTranslatef (3.75, 3.0, 0.0);
      drawObject();
    glPopMatrix();

    glPushMatrix();
      glTranslatef (3.75, 0.0, 0.0);
      drawObject();
    glPopMatrix();

    glPushMatrix();
      glTranslatef (3.75, -3.0, 0.0);
      drawObject();
    glPopMatrix();

    glFlush();
}

void myReshape(int w, int h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho (-6.0, 6.0, -4.5, 4.5, -6.0, 6.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

void tecladoEspecial(int key, int mx, int my) {
	switch(key) {
		case GLUT_KEY_F1:
			figure = 1;
		break;
		
		case GLUT_KEY_F2:
			figure = 2;
		break;
		
		case GLUT_KEY_F3:
			figure = 3;
		break;
	}
	glutPostRedisplay();
}

int main(int argc, char** argv){
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize (600, 450);
    glutCreateWindow("Materiales 2");
    myinit();
    glutReshapeFunc(myReshape);
    glutDisplayFunc(display);
    glutSpecialFunc(tecladoEspecial);
    glutMainLoop();
    return 0;
}
